//
//  KQMessageRecallContent.swift
//  KQChatKit
//
//  Created by kangqiao on 2021/9/15.
//

import UIKit

class KQMessageRecallContent: NSObject, KQMessageContentType {
    open class var viewType: KQMessageContentViewType.Type {
        return KQMessageRecallContentView.self
    }
    
    public init(text: String) {
        self.text = text
        super.init()
    }
    
    public weak var delegate: KQMessageDelegate?
    open var layoutMargins: UIEdgeInsets = .zero
    open var text: String
    
    
    open func sizeThatFits(_ size: CGSize) -> CGSize {
        
        let attr = NSMutableAttributedString(string: text, attributes: convertToOptionalNSAttributedStringKeyDictionary([
            convertFromNSAttributedStringKey(NSAttributedString.Key.font): UIFont(name: KQCHAT_FONT_NAME, size: 12) as Any,
            convertFromNSAttributedStringKey(NSAttributedString.Key.foregroundColor): UIColor.white,
            ]))
        
        return CGSize(width: attr.size().width + 11, height: 18)
    }
}
// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertToOptionalNSAttributedStringKeyDictionary(_ input: [String: Any]?) -> [NSAttributedString.Key: Any]? {
    guard let input = input else { return nil }
    return Dictionary(uniqueKeysWithValues: input.map { key, value in (NSAttributedString.Key(rawValue: key), value)})
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromNSAttributedStringKey(_ input: NSAttributedString.Key) -> String {
    return input.rawValue
}
